package chap3_1;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;

/**
 * @author https://gitee.com/W_Jun
 * @date 2021-12-13 15:41
 * @Description
 */
public class FileInputStreamDemo {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("chapter03-字符流\\a.txt");
        int by;
        while ((by = fis.read()) != -1) {
            System.out.print((char) by);//a.txt中实际是“abc中国”,但是，控制台输出“abcä¸­å½”
        }
        fis.close();
        System.out.println("---------");

        String s1 = "abc";
        String s2 = "中国";
        byte[] bys1 = s1.getBytes();
        byte[] bys2 = s2.getBytes();//默认是UTF-8编码
        System.out.println(Arrays.toString(bys1));
        System.out.println(Arrays.toString(bys2));
        byte[] bys21 = s2.getBytes("UTF-8");
        System.out.println("指定UTF-8编码时，" + Arrays.toString(bys21));
        byte[] bys22 = s2.getBytes("GBK");
        System.out.println("指定GBK编码时，" + Arrays.toString(bys22));
    }
}
